unit uExportDecl_mainmenu;

interface
        uses  SysUtils, Classes, Forms, Windows, Graphics, Controls, StdCtrls,
     ExtCtrls, ComCtrls, Menus
     ;




function	CreateMainMenu( ownerForm :pointer 	) :pointer; stdcall;

function CreateMainMenuItem(
		pMainMenu :Pointer;
		const parent_item_caption :PAnsiChar;
		const caption :PAnsiChar
		) :pointer; stdcall;



implementation
     uses uExportGuiEventCallbackpas  ;



function	CreateMainMenu( ownerForm :pointer 	) :pointer; stdcall;
    var mm :TMainMenu;
    var frm :TForm;
begin
  frm := TForm(ownerForm);
  mm := TMainMenu.Create(frm);
  frm.Menu := mm;

  result := Pointer( mm );
end;


function CreateMainMenuItem(
		pMainMenu :Pointer;
		const parent_item_caption :PAnsiChar;
		const caption :PAnsiChar
		                      ) :pointer; stdcall;

  var  mm :TMainMenu;
       par :TMenuItem;
  var  n :TMenuItem;
begin
    result := nil;
    mm := TMainMenu(pMainMenu);
    n := TMenuItem.Create(mm);
    n.OnClick := g_helper.OnMainMenuItemClick;

    if(parent_item_caption = nil)
    then
      begin

        n.Caption := caption;
        mm.Items.Add(n);
        Result := Pointer(n);
        Exit;
      end;

    par := mm.Items.Find(parent_item_caption);

    if(par = nil)
    then
      begin
          // error
          result := nil;
          Exit;
      end;


    n.Caption := caption;
    par.Add(n);
    Result := Pointer(n);

end;

end.
